/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * KUnos.java
 *
 * Created on 09.03.2010., 23.54.58
 */

package KLforme;

import klijent.KlijentVeza;
import model.Paket;
import model.Radnik;

/**
 *
 * @author Dejan
 */
public class KUnos extends javax.swing.JFrame {
    private final KlijentVeza k;
    private Radnik r;

    /** Creates new form KUnos */
   

    KUnos(KlijentVeza k) {
        this.k=k;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbDajSifru = new javax.swing.JButton();
        jbUnesi = new javax.swing.JButton();
        jtfSifraRad = new javax.swing.JTextField();
        jtfIme = new javax.swing.JTextField();
        jtfPrezime = new javax.swing.JTextField();
        jtfAdresa = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jbDajSifru.setText("Dodeli sifru");
        jbDajSifru.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbDajSifruActionPerformed(evt);
            }
        });

        jbUnesi.setText("Unesi");
        jbUnesi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbUnesiActionPerformed(evt);
            }
        });

        jtfIme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfImeActionPerformed(evt);
            }
        });

        jLabel1.setText("ime");

        jLabel2.setText("prezime");

        jLabel3.setText("sifra");

        jLabel4.setText("adresa");

        jLabel5.setText("UNOS RADNIKA");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(69, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfAdresa)
                            .addComponent(jtfIme, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jbDajSifru)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfSifraRad, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jtfPrezime, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11))
                    .addComponent(jbUnesi, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(123, 123, 123))
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(jLabel5)
                .addContainerGap(288, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSifraRad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbDajSifru))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfIme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfPrezime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfAdresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(29, 29, 29)
                .addComponent(jbUnesi)
                .addGap(40, 40, 40))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtfImeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfImeActionPerformed
        
    }//GEN-LAST:event_jtfImeActionPerformed

    private void jbUnesiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbUnesiActionPerformed
      r= new Radnik(jtfSifraRad.getText(),jtfIme.getText(),jtfPrezime.getText(),jtfAdresa.getText() );
        Paket p =new Paket("unos radnika");
        p.setTovar((Object)r);
        k.posalji(p);
    }//GEN-LAST:event_jbUnesiActionPerformed

    private void jbDajSifruActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbDajSifruActionPerformed
         Paket p =new Paket("zahtev nove sifre");
         k.posalji(p);

         java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {


               // new KLogin().setVisible(true);
               while(true){
                  if(!(k.getSifra()==null) ){
                        jtfSifraRad.setText(k.getSifra());

                      k.setSifra(null);
                      break;
                  }


               }
            }
        });
    }//GEN-LAST:event_jbDajSifruActionPerformed

    /**
    * @param args the command line arguments
    */



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JButton jbDajSifru;
    private javax.swing.JButton jbUnesi;
    private javax.swing.JTextField jtfAdresa;
    private javax.swing.JTextField jtfIme;
    private javax.swing.JTextField jtfPrezime;
    private javax.swing.JTextField jtfSifraRad;
    // End of variables declaration//GEN-END:variables

}
